package com.example.gametouch;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Game_Touch extends Activity implements OnClickListener {
	private Button newGame, tiepTuc, huongDan, exit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_game__touch);
		newGame = (Button) findViewById(R.id.newGame);
		tiepTuc = (Button) findViewById(R.id.tiepTuc);
		huongDan = (Button) findViewById(R.id.huongDan);
		exit = (Button) findViewById(R.id.thoat);
		newGame.setOnClickListener(this);
		tiepTuc.setOnClickListener(this);
		huongDan.setOnClickListener(this);
		exit.setOnClickListener(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.game__touch, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		
		switch (v.getId()) {
		case R.id.newGame:
			/*
			 * final String[] item = new String[] { "DỄ", "BÌNH THUÒNG", "KHÓ"
			 * }; AlertDialog.Builder dokho = new
			 * AlertDialog.Builder(Game_Touch.this); dokho.setTitle("Độ Khó");
			 * dokho.setItems(item, new DialogInterface.OnClickListener() {
			 * 
			 * @Override public void onClick(DialogInterface dialog, int which)
			 * { // chon do kho o day Intent de = new Intent(Game_Touch.this,
			 * NewGame.class); switch (which) { case 0:
			 * 
			 * int dokho1 = 1000; int biendem = 40000; de.putExtra("BIENDEM",
			 * biendem); de.putExtra("DOKHO", dokho1);
			 * 
			 * break; case 1: int dokho2 = 800;
			 * 
			 * de.putExtra("DOKHO", dokho2); break; case 2: int dokho3 = 500;
			 * 
			 * de.putExtra("DOKHO", dokho3);
			 * 
			 * break;
			 * 
			 * } startActivity(de); } }); dokho.show();
			 */
			Intent it1 = new Intent(this, Player.class);
			startActivity(it1);
			break;
		case R.id.tiepTuc:
			try {
				Intent it = new Intent(Game_Touch.this, NewGame.class);
				Bundle bd = new Bundle();
				SharedPreferences preferences = getSharedPreferences("SAVE",
						Activity.MODE_PRIVATE);
				int n = preferences.getInt("DIEM", 0), vt = preferences.getInt(
						"VITRI", 0);
				int lv = preferences.getInt("Level", 1000);
				/* String time = preferences.getString("TIME", "30000"); */

				int time = preferences.getInt("TIME", 0);
				String Name = preferences.getString("NAME", "player");
				boolean co = true;
				bd.putBoolean("CO", co);
				bd.putInt("DS", n);
				bd.putInt("VT", vt);
				bd.putInt("LV", lv);
				bd.putInt("TIME", time);
				bd.putString("NAME", Name);

				/* bd.putString("TIME", time); */
				Log.d("LAY", "n=" + n + " " + "Vitri=" + vt + " " + "level="
						+ lv + " " + "time=" + Name);
				it.putExtras(bd);
				if (bd != null)
					startActivity(it);

				/*
				 * Intent tieptuc1 = new Intent(Game_Touch.this, NewGame.class);
				 * Bundle tt = new Bundle(); tt.putString("DEM", chuoi);
				 * tieptuc1.putExtras(tt); Log.d("diemnhan", "diemlayra:"+
				 * chuoi); startActivity(tieptuc1);
				 */
			} catch (Exception e) {
				// TODO: handle exception
				Toast.makeText(getApplicationContext(), "không đọc được",
						Toast.LENGTH_SHORT).show();
			}

			break;

		case R.id.huongDan:
			Intent hd = new Intent(Game_Touch.this, HuongDan.class);
			startActivity(hd);
			break;
		case R.id.thoat:
			finish();

		default:
			break;
		}

	}

}
